package com.yunzheng.studyLeaveSystem.modules.user.user_info.servlet; /**
 * Created with IntelliJ IDEA.
 *
 * @Author: YunZheng
 * @Date: 2023/02/08/15:49
 * @Description:
 */

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yunzheng.studyLeaveSystem.modules.response.ResponseWrapper;
import com.yunzheng.studyLeaveSystem.modules.user.user_info.service.User_infoService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
/*
 *修改个人信息
 */
@WebServlet(name = "UpdateUser_infoServlet", value = "/UpdateUser_infoServlet")
public class UpdateUser_infoServlet extends HttpServlet {
    private User_infoService user_infoService = new User_infoService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        session.setAttribute("id",7);
        int id = (int) session.getAttribute("id");
        //获取请求体数据
        BufferedReader reader = request.getReader();
        String readLine = reader.readLine();
        //将JSON字符转化为JAVA对象
        JSONObject jsonObject = JSON.parseObject(readLine);
        String phone_num = jsonObject.getString("phone_num");
        String username = jsonObject.getString("username");
        String gender = jsonObject.getString("gender");
        String term = jsonObject.getString("term");
        String direction = jsonObject.getString("direction");
        String constellation = jsonObject.getString("constellation");
        String hometown = jsonObject.getString("hometown");
        String birthday = jsonObject.getString("birthday");
        String QQ = jsonObject.getString("QQ");
        String wechat = jsonObject.getString("wechat");
        String email = jsonObject.getString("email");
        String signature = jsonObject.getString("signature");
        ResponseWrapper responseWrapper = null;
        try {
            responseWrapper = user_infoService.updateUser_info(username, gender, term, direction,constellation, hometown, phone_num,birthday, QQ, wechat, email, signature,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        String s = JSON.toJSONString(responseWrapper);
        response.getWriter().write(s);
        System.out.println(s);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
    }
}
